package com.tr.state;

/**
 * @author TRasdzz
 * @since  2021/3/10 16:20
 * @version 1.0
 */
//模拟网络延时:放大问题的发生行
public class TestSleep01 implements Runnable{
    //票的总数
    private int ticketNum = 10;

    @Override
    public void run() {
        while (true){
            //模拟延时
            if (ticketNum < 0){
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + " ---> 拿到了第" + ticketNum-- + "张票");
        }
    }

    public static void main(String[] args) {
        TestSleep01 ticket = new TestSleep01();

        new Thread(ticket,"小明").start();
        new Thread(ticket,"小红").start();
        new Thread(ticket,"黄牛").start();
    }
}
